<!DOCTYPE html>
<html lang='zh-CN'>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>会员机制配置表</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/materialdesignicons.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.min.css" rel="stylesheet">
    <link href="js/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">

</head>
<body>
<div class="container-fluid p-t-15">

    <div class="row">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header"><h4>佣金设置</h4></div>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade active in">

                        <form class="form-inline" method="post" id="searchForm">
                            <div class="form-group">
                                <label>配置名称:</label>
                                <input type="text" class="form-control" name="configurationLevel">
                            </div>

                            <div class="form-group">
                                <button class="btn btn-info btn_query btn-round"  type="button" id="searchFormBtn" >查询</button>
                            </div>
                            <div class="form-group">
                                <button class="btn btn-warning btn_query btn-round" type="button" id="editBtn">编辑</button>
                            </div>
                        </form>
                        <table id="list_data"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>


<!-- 奖品表-添加与编辑模态框 -->
<div class="modal fade" id="addOrEditModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            </div>
            <div class="modal-body">
                <form id="addOrEditForm" method="post">
                    <input type="hidden" class="form-control" id="id" name="id" required>
                    <div class="row">
                        <div class="col-xs-12">
                            <label for="configurationLevel" class="control-label">配置名称：</label>
                            <input type="text" class="form-control" id="configurationLevel" name="configurationLevel" required>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-12">
                            <label for="oneLevel" class="control-label" id="textOne">一级：</label>
                            <input type="text" class="form-control" id="oneLevel" name="oneLevel" onkeyup="clearNoNum(this)" required>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-xs-12" id="two">
                            <label for="twoLevel" class="control-label" id="textTwo">二级：</label>
                            <input type="text" class="form-control" id="twoLevel" name="twoLevel" onkeyup="clearNoNum(this)" required>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" id="Subtn" class="btn btn-primary">保存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

</div>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table.js"></script>
<script type="text/javascript" src="js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.version.js"></script>
<script type="text/javascript" src="js/zero2one/zero2one.core.js"></script>
<script type="text/javascript" src="js/dropzone/min/dropzone.min.js"></script>
<script type="text/javascript" src="js/bootstrapvalidator/dist/js/bootstrapValidator.js"></script>
<!-- bootstrap表单验证插件 -->
<script type="text/javascript" src="js/bootstrap-validator-master/dist/validator.js"></script>
<!-- jquery-form表单提交插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.form.js"></script>
<!-- bootstrap弹出框插件 -->
<script type="text/javascript" src="js/jquery.bootstrap.min.js"></script>
<!-- 表单填充插件 -->
<script type="text/javascript" src="js/jquery-form/jquery.formloader.js"></script>

<!--消除数字以外的字符插件-->
<script type="text/javascript" src="js/inputmoney.js"></script>
<script type="text/javascript">



    //设置表头
    var columns = [
        {checkbox: true},
        {field: 'id',visible:false},
        {field: 'configurationLevel',title: "配置名称"},
        {field: 'oneLevel',formatter: function (value, row, index) {
            if (row.type==1  || row.type==3){
                return "一级:&nbsp;&nbsp;&nbsp;"+value+"%";
            }else if (row.type==4){
                return "每周:&nbsp;&nbsp;&nbsp;"+value+"次";
            }else {
                return "无";
            }
            }},
        {field: 'twoLevel',formatter: function (value,row) {
            if(row.type==3){
                return "二级:&nbsp;&nbsp;&nbsp;"+value+"%";
            }else if (value==null || value==''){
                    return '无';
            }else if(row.type==4){
                return '最小金额：&nbsp;&nbsp;&nbsp;'+value+"元";
            }
            }},
        {field: 'type',title: '类型',visible:false},
        {field: 'marketKg',formatter: function (value,row) {
                if (row.type==1 && row.oneLevel==0){//判断站长佣金（一级百分比如果为零）
                   return "无";
                }else if (row.type != 1 && row.oneLevel==0 && row.twoLevel==0){
                    return "无";
                }else if (value==0){
                return "     <div class=\"form-group m-b-1\">\n" +
                    "    <div>商场开关：</div>\n" +
                    "    <div>\n" +
                    "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                    "            <input type=\"checkbox\"  onclick=\'marketsKg(checked,"+row.id+")\'>\n" +
                    "            <span></span>\n" +
                    "        </label>\n" +
                    "    </div>\n" +
                    "</div>";
            }else {
                return "     <div class=\"form-group m-b-1\">\n" +
                    "    <div>商场开关：</div>\n" +
                    "    <div>\n" +
                    "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                    "            <input type=\"checkbox\" checked=\"checked\"  onclick=\'marketsKg(checked,"+row.id+")\'>\n" +
                    "            <span></span>\n" +
                    "        </label>\n" +
                    "    </div>\n" +
                    "</div>";
            }
            }},
        {field: 'postKg',formatter: function (value,row) {
                if (row.type==1 && row.oneLevel==0){//判断站长佣金（一级百分比如果为零）
                    return "无";
                }else if (row.type != 1 && row.oneLevel==0 && row.twoLevel==0){
                    return "无";
                }else if (value==0){
                    return "     <div class=\"form-group m-b-1\">\n" +
                        "    <div>驿站开关：</div>\n" +
                        "    <div>\n" +
                        "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                        "            <input type=\"checkbox\"  onclick=\'postsKg(checked,"+row.id+")\'>\n" +
                        "            <span></span>\n" +
                        "        </label>\n" +
                        "    </div>\n" +
                        "</div>";
                }else {
                    return "     <div class=\"form-group m-b-1\">\n" +
                        "    <div>驿站开关：</div>\n" +
                        "    <div>\n" +
                        "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                        "            <input type=\"checkbox\" checked=\"checked\"  onclick=\'postsKg(checked,"+row.id+")\'>\n" +
                        "            <span></span>\n" +
                        "        </label>\n" +
                        "    </div>\n" +
                        "</div>";
                }
            }},
        {field: 'migrantKg',formatter: function (value,row) {
                if (row.type==1 && row.oneLevel==0){//判断站长佣金（一级百分比如果为零）
                    return "无";
                }else if (row.type != 1 && row.oneLevel==0 && row.twoLevel==0){
                    return "无";
                }else if (value==0){
                    return "     <div class=\"form-group m-b-1\">\n" +
                        "    <div>候鸟开关：</div>\n" +
                        "    <div>\n" +
                        "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                        "            <input type=\"checkbox\"  onclick=\'migrantsKg(checked,"+row.id+")\'>\n" +
                        "            <span></span>\n" +
                        "        </label>\n" +
                        "    </div>\n" +
                        "</div>";
                }else {
                    return "     <div class=\"form-group m-b-1\">\n" +
                        "    <div>候鸟开关：</div>\n" +
                        "    <div>\n" +
                        "        <label class=\"lyear-switch switch-solid switch-success\">\n" +
                        "            <input type=\"checkbox\" checked=\"checked\"  onclick=\'migrantsKg(checked,"+row.id+")\'>\n" +
                        "            <span></span>\n" +
                        "        </label>\n" +
                        "    </div>\n" +
                        "</div>";
                }
            }},
    ];

    //进入主界面加载数据
    zero2one.datagrid("list_data", "/remote/mechanism/list",function (params) {
        return $.extend(zero2one.tableInitParam(params), zero2one.form2json("searchForm"));
    }, columns);

    //点击查询按钮重新加载页面数据
    $("#searchFormBtn").click(function () {
        $('#list_data').bootstrapTable('refresh');
    });


    //点击编辑按钮弹出模态框
    $("#editBtn").click(function () {

        $('#two').show();//显示出隐藏的<idv>
        //获取选中行的数据
        var datas = $('#list_data').bootstrapTable('getSelections');
        //判断是否选中行数据，如果没有则提示
        if(datas.length == 1){

            //填充表单
            $("#addOrEditForm").formloader({data: datas[0]});
            if (datas[0].type==1){ //隐藏id为1的编辑模态框二级字段
                $('#two').hide();
            }else if (datas[0].type!=4){ //隐藏id为1的编辑模态框二级字段
                $('#textOne').text("一级");//重新赋值
                $('#textTwo').text("二级");
            }else if(datas[0].type==4){
                $('#textOne').text("每周");
                $('#textTwo').text("最小金额");
            }

        }else{
            $.messager.alert("温馨提示", "请选择一条数据操作");
            return;
        }
        $("#addOrEditModal").modal("show");
    });



    //保存按钮的点击事件
    $("#Subtn").click(function () {
        zero2one.request("/remote/mechanism/edit",$("#addOrEditForm").serialize(),function (data) {
            if (data.success) {
                window.location.reload();
            }else {
                $.messager.alert("温馨提示", data.msg)
            }
        });
    });

    //商场开关（按钮）
    function marketsKg(kg,ids){
        $.post("/remote/mechanism/marketKgEdit", {"kg": kg,"ids": ids},function (data) {
            if (data.success) {
                $.messager.alert("提示", "您已经编辑开关成功");
            } else {
                $.messager.alert("温馨提示", data.msg)
            }
        },"json");
    }

    //驿站开关（按钮）
    function postsKg(kg,ids){
        $.post("/remote/mechanism/postKgEdit", {"kg": kg,"ids": ids},function (data) {
            if (data.success) {
                $.messager.alert("提示", "您已编辑开关成功");
            } else {
                $.messager.alert("温馨提示", data.msg)
            }
        },"json");
    }


    //候鸟开关（按钮）
    function migrantsKg(kg,ids){
        $.post("/remote/mechanism/migrantKgEdit", {"kg": kg,"ids": ids},function (data) {
            if (data.success) {
                $.messager.alert("提示", "您已编辑开关成功");
            } else {
                $.messager.alert("温馨提示", data.msg)
            }
        },"json");
    }

</script>
</body>
</html>
